home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 1.6 KB | 58 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CMyFileStream.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
- // A subclass of LFileStream which is useful for reading in integers.
-
- #include "CMyFileStream.h"
-
- // ---------------------------------------------------------------------------
- // • CMyFileStream(FSSpec&)
- // ---------------------------------------------------------------------------
- // Contruct a FileStream from a Toolbox File System Specification
-
- CMyFileStream::CMyFileStream(
- FSSpec &inFileSpec)
- : LFileStream(inFileSpec)
- {
- }
-
- // ---------------------------------------------------------------------------
- // • ReadInt
- //
- // Called by: CGraphGADoc::OpenFile
- // ---------------------------------------------------------------------------
- // Try to read an UNSIGNED integer from the data fork of a FileStream
- // to *outInt. Return true if *we think* operation was succesful...
-
- Boolean
- CMyFileStream::ReadInt(
- Int16 &outInt )
- {
- char theChar;
- Int16 theNbr = 0;
- Int32 kSizeOfChar = sizeof(theChar);
-
- // Go past everything until we find the first digit
-
- do {
- if ( ReadData( &theChar, kSizeOfChar ) != kSizeOfChar )
- return false;
-
- } while (! ('0' <= theChar && theChar <= '9' ));
-
- // Update the integer as long as there are digits left.
- // Yes, overflow *is* possible so use with caution...
-
- do {
- theNbr = (theNbr * 10) + (theChar - '0');
- if ( ReadData( &theChar, kSizeOfChar ) != kSizeOfChar )
- break;
-
- } while ( '0' <= theChar && theChar <= '9' );
-
- outInt = theNbr;
-
- return true;
- }
-
-